package com.cgs.query.demo.client

import com.cgs.query.client.helper.QueryCenterHelper
import com.cgs.query.service.IQueryService
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import io.swagger.annotations.ApiParam
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("/test")
@Api(description = "测试服务端服务")
open class TestController {

    @Autowired
    private lateinit var queryService: IQueryService
    @Autowired
    private lateinit var queryCenterHelper: QueryCenterHelper

    @GetMapping("/r/{projectName}/{defineName}")
    @ApiOperation(value = "执行查询定义,远程执行")
    fun executeR(@ApiParam(value = "项目名称") @PathVariable() projectName: String, @ApiParam(value = "定义名称") @PathVariable defineName: String): Any? {
        return queryService.execute(projectName, defineName, mapOf(), 3)
    }

    @PostMapping("/l/{projectName}/{defineName}")
    @ApiOperation(value = "执行查询定义,本地执行,需要配置quasar.projectNames参数")
    fun executeL(@ApiParam(value = "项目名称") @PathVariable() projectName: String, @ApiParam(value = "定义名称") @PathVariable defineName: String, @ApiParam(value = "定义参数") @RequestBody param: Map<String, Any>): Any? {
        return queryService.execute(projectName, defineName, param, 3)
    }


    @GetMapping("/a/{defineName}")
    @ApiOperation(value = "分页查询")
    fun executeA(@ApiParam(value = "定义名称") @PathVariable defineName: String): Any? {
        return queryCenterHelper.paginateExecute(defineName, 1, 5)
    }

    @GetMapping("/b/{defineName}")
    @ApiOperation(value = "执行查询定义,远程执行")
    fun executeB(@ApiParam(value = "定义名称") @PathVariable defineName: String): Any? {
        return queryCenterHelper.singleExecute(defineName)
    }

    @GetMapping("/c/{defineName}")
    @ApiOperation(value = "执行查询定义,远程执行")
    fun executeC(@ApiParam(value = "定义名称") @PathVariable defineName: String): Any? {
        return queryCenterHelper.singleExecute(defineName, LinkedHashMap::class.java)
    }

}
